using UnityEngine;

public class Projectile : MonoBehaviour
{
	public int damageBullet;

	private int dameArrow;

	public int TypeOfBullet;

	private float distance;

	private int[] damageNormal = new int[90]
	{
		25,
		50,
		75,
		100,
		125,
		150,
		175,
		200,
		225,
		250,
		275,
		300,
		325,
		350,
		375,
		400,
		425,
		450,
		475,
		600,
		630,
		680,
		710,
		770,
		850,
		930,
		960,
		990,
		1020,
		1050,
		1100,
		1150,
		1200,
		1300,
		1400,
		1500,
		1600,
		1700,
		1800,
		1900,
		2000,
		2100,
		2200,
		2300,
		2400,
		2500,
		2600,
		2700,
		2800,
		2900,
		3000,
		3400,
		3500,
		3600,
		3700,
		3800,
		4000,
		4200,
		4400,
		4700,
		5000,
		5500,
		6000,
		6500,
		7000,
		7500,
		8000,
		8500,
		9000,
		9500,
		10500,
		11000,
		11300,
		11500,
		11800,
		12200,
		12600,
		13100,
		13600,
		14100,
		14600,
		15200,
		15800,
		16200,
		16800,
		16400,
		17000,
		17800,
		18600,
		20000
	};

	private int[] dameCross = new int[6]
	{
		16000,
		20000,
		25000,
		32000,
		40000,
		50000
	};

	private int[] dameBulletKatana = new int[6]
	{
		4000,
		5000,
		6500,
		8000,
		10000,
		12000
	};

	private int[] dameBulletCloud = new int[6]
	{
		7500,
		9000,
		12500,
		14000,
		17000,
		20000
	};

	private int[] dameBulletPike = new int[6]
	{
		24000,
		32000,
		42000,
		52000,
		62000,
		75000
	};

	private int[] dameBulletZed = new int[6]
	{
		45000,
		60000,
		75000,
		95000,
		115000,
		140000
	};

	private int dameMaxCross;

	private int dameCrossFire;

	private int dameKatana;

	private int dameMaxKatana;

	private int dameCloud;

	private int dameMaxCloud;

	private int damePike;

	private int dameMaxPike;

	private int dameZed;

	private int dameMaxZed;

	private int dameBullet1Boss;

	private int dameBullet2Boss;

	private int[] tangdamePlayer = new int[6]
	{
		0,
		10,
		25,
		45,
		70,
		100
	};

	public GameObject EffButllet4Cross;

	private void Start()
	{
		UnityEngine.Object.Destroy(base.gameObject, 1.5f);
		if (!GameManager.isHard)
		{
			switch (GameManager.map)
			{
			case 1:
				dameArrow = 100;
				break;
			case 2:
				dameArrow = 200;
				break;
			case 3:
				dameArrow = 400;
				break;
			case 4:
				dameArrow = 800;
				break;
			case 5:
				dameArrow = 1000;
				break;
			case 6:
				dameArrow = 2000;
				break;
			}
			dameBullet1Boss = 30000;
			dameBullet2Boss = 50000;
		}
		else
		{
			switch (GameManager.map)
			{
			case 1:
				dameArrow = 800;
				break;
			case 2:
				dameArrow = 1200;
				break;
			case 3:
				dameArrow = 1600;
				break;
			case 4:
				dameArrow = 2500;
				break;
			case 5:
				dameArrow = 3500;
				break;
			case 6:
				dameArrow = 5000;
				break;
			}
			dameBullet1Boss = 60000;
			dameBullet2Boss = 100000;
		}
		if (TypeOfBullet == 1)
		{
			dameKatana = dameBulletKatana[GameManager.levelUpgrade[4]] + damageNormal[GameManager.levelPlayer - 1];
			dameMaxKatana = dameKatana + dameKatana * tangdamePlayer[GameManager.levelUpgrade[0]] / 100;
		}
		if (TypeOfBullet > 1 && TypeOfBullet < 4)
		{
			dameCloud = dameBulletCloud[GameManager.levelUpgrade[5]] + damageNormal[GameManager.levelPlayer - 1];
			dameMaxCloud = dameCloud + dameCloud * tangdamePlayer[GameManager.levelUpgrade[0]] / 100;
		}
		if ((TypeOfBullet >= 4 && TypeOfBullet <= 6) || (TypeOfBullet > 9 && TypeOfBullet < 15))
		{
			dameCrossFire = dameCross[GameManager.levelUpgrade[6]] + damageNormal[GameManager.levelPlayer - 1];
			dameMaxCross = dameCrossFire + dameCrossFire * tangdamePlayer[GameManager.levelUpgrade[0]] / 100;
		}
		if (TypeOfBullet == 15)
		{
			damePike = dameBulletPike[GameManager.levelUpgrade[7]] + damageNormal[GameManager.levelPlayer - 1];
			dameMaxPike = damePike + damePike * tangdamePlayer[GameManager.levelUpgrade[0]] / 100;
		}
		if (TypeOfBullet > 15 && TypeOfBullet < 18)
		{
			dameZed = dameBulletZed[GameManager.levelUpgrade[9]] + damageNormal[GameManager.levelPlayer - 1];
			dameMaxZed = dameZed + dameZed * tangdamePlayer[GameManager.levelUpgrade[0]] / 100;
		}
	}

	private void OnTriggerEnter2D(Collider2D target)
	{
		if (target.gameObject.tag == "Enemy")
		{
			switch (TypeOfBullet)
			{
			case 7:
			case 8:
			case 9:
			case 10:
			case 11:
			case 12:
			case 13:
			case 14:
				break;
			case 0:
				target.gameObject.GetComponent<EnemyController>().Hit_Player(damageBullet + damageBullet * tangdamePlayer[GameManager.levelUpgrade[0]] / 100, a: true, 2);
				UnityEngine.Debug.Log(damageBullet + damageBullet * tangdamePlayer[GameManager.levelUpgrade[0]] / 100);
				break;
			case 1:
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxKatana * 2, a: true, 2);
				break;
			case 2:
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxCloud, a: true, 2);
				break;
			case 3:
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxCloud * 3 / 2, a: true, 2);
				break;
			case 4:
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxCross, a: false, 1);
				UnityEngine.Object.Destroy(base.gameObject);
				break;
			case 5:
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxCross * 2, a: true, 2);
				break;
			case 6:
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxCross, a: true, 0);
				break;
			case 15:
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxPike, a: true, 2);
				break;
			case 16:
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxZed, a: true, 0);
				break;
			case 17:
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxZed * 2, a: true, 2);
				break;
			}
		}
		else if (target.gameObject.tag == "Boss")
		{
			if (TypeOfBullet == 4)
			{
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxCross, a: false, 0);
				UnityEngine.Object.Destroy(base.gameObject);
			}
			else if (TypeOfBullet == 5)
			{
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxCross * 2, a: true, 0);
			}
			else if (TypeOfBullet == 6)
			{
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxCross, a: true, 0);
			}
			else if (TypeOfBullet == 15)
			{
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxPike, a: true, 0);
			}
			else if (TypeOfBullet == 16)
			{
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxZed, a: true, 0);
			}
			else if (TypeOfBullet == 17)
			{
				target.gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxZed * 2, a: true, 0);
			}
		}
		else if (target.gameObject.tag == "Platform")
		{
			switch (TypeOfBullet)
			{
			case 1:
				GetComponent<Rigidbody2D>().gravityScale = 0f;
				GetComponent<BoxCollider2D>().enabled = false;
				GetComponent<Rigidbody2D>().velocity = Vector2.zero;
				GetComponent<tk2dSprite>().SetSprite("muyeshengfeng01");
				break;
			case 10:
			{
				GameObject obj2 = UnityEngine.Object.Instantiate(EffButllet4Cross, base.transform.position, Quaternion.identity);
				UnityEngine.Object.Destroy(obj2, 0.8f);
				KillEnemy();
				UnityEngine.Object.Destroy(base.gameObject);
				break;
			}
			case 11:
			{
				GameObject obj = UnityEngine.Object.Instantiate(EffButllet4Cross, base.transform.position, Quaternion.identity);
				UnityEngine.Object.Destroy(obj, 0.8f);
				KillEnemy();
				UnityEngine.Object.Destroy(base.gameObject);
				break;
			}
			}
		}
		else if (target.gameObject.tag == "Player")
		{
			switch (TypeOfBullet)
			{
			case 7:
				target.gameObject.GetComponent<PlayerController>().Hit_Enemy(dameArrow);
				UnityEngine.Object.Destroy(base.gameObject);
				break;
			case 8:
				target.gameObject.GetComponent<PlayerController>().Hit_Enemy(dameBullet1Boss);
				UnityEngine.Object.Destroy(base.gameObject);
				break;
			case 9:
				target.gameObject.GetComponent<PlayerController>().Hit_Enemy(dameBullet2Boss);
				break;
			}
		}
	}

	private void KillEnemy()
	{
		for (int i = 0; i < GameManager.AllEnemy.Count; i++)
		{
			distance = Vector3.Distance(base.transform.position, GameManager.AllEnemy[i].transform.position);
			if (distance < 2f)
			{
				GameManager.AllEnemy[i].gameObject.GetComponent<EnemyController>().Hit_Player(dameMaxCross * 2, a: true, 2);
			}
		}
	}
}
